package com.appleyk.config;

import com.appleyk.component.MyFilter;
import com.appleyk.component.MyListener;
import com.appleyk.component.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**
 * <p>越努力，越幸运</p>
 *
 * @author appleyk
 * @version V.0.1.1
 * @blob https://blog.csdn.net/appleyk
 * @date created on  9:58 下午 2021/2/27
 */
@Configuration
public class BootConfig {

    @Bean
    public ServletRegistrationBean<MyServlet> myServlet() {
        return new ServletRegistrationBean(new MyServlet(), "/myServlet");
    }

    @Bean
    public FilterRegistrationBean<MyFilter> myFilter(){
        FilterRegistrationBean<MyFilter> myFilter = new
                FilterRegistrationBean<>();
        myFilter.setFilter(new MyFilter());
        myFilter.setUrlPatterns(Arrays.asList("/myServlet","/myFilter"));
        return myFilter;
    }

    @Bean
    public ServletListenerRegistrationBean<MyListener> myListener(){
         return new ServletListenerRegistrationBean<>(new MyListener());
    }

}
